package practice;

import java.util.*;

public class Solution{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        SortedMap map = new TreeMap<Integer,Integer>();
        int k,v;
        for(int i=0;i<n;i++){
            k = sc.nextInt();
            v = sc.nextInt();
            if(map.containsKey(k)){
                map.put(k,v + Integer.parseInt(map.get(k).toString()));
            }
            map.put(k,v);
        }
        map.forEach((key, value) -> {
            System.out.println(key+" "+value);
        });
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.forEach((key) -> {
            System.out.println(key);
        });
    }
}
